#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1e6 + 10;
struct node
{
	int l;
	int r;
}a[N];

bool cmp(node& x1, node& x2)
{
	return x1.l < x2.l;
}

int main()
{
	int n; cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x, y; cin >> x >> y;
		a[i].l = x; a[i].r = y;
	}

	sort(a + 1, a + 1 + n, cmp);
     
	int sum = 1; 
	for (int i = 2; i <= n; i++)
	{
		if (a[i].l<a[i-1].r)
		{
			a[i].r = min(a[i-1].r, a[i].r);
		 }
		else
		{
			sum++;
		}

	}
	cout << sum;
	return 0;
}
